<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Alishipment extends Backend {

	public function __construct()
	{
		parent::__construct();
        $this->load->model(['aliship_model']);
		$this->data['page_home']  = lang('lang_dashboard');
        $this->data['page_title'] = '速卖通物流追踪';
        
        $this->data['statetype']=[
			"0"=>'运输中',
			"1"=>'已妥投',
            "2"=>'争议中',
            "3"=>'重购中'
		];
		$this->data['statelabel']=[
			"0"=>'label-danger',
			"1"=>'label-success',
            "2"=>'label-warning',
            "3"=>'label-info',			
        ];
        

	}

    public function index()
	{
		// Title
		$this->data['meta_title'] = $this->data['page_title'];

		// Breadcrumbs
		$this->data['array_breadcrumbs'] = array(
			$this->data['page_home']  => 'backend',
			$this->data['page_title'] => 'backend/alishipment'
		);

		$page=max(1,(int) $this->input->get('page'));
        $key=trim($this->input->get('keyword'));
        $sort=trim($this->input->get('sort'));
        if(empty($sort))
        {
            $sort="paytime_desc";
        }
        $state=trim($this->input->get('state'));
        
        
        $page_data=$this->aliship_model->getpage($page,$key,$sort,$state);
        $this->data['data']=$page_data["data"];
        $this->data['pager']=$page_data["pager"];

        $this->data['total']=$page_data["total"];
        $this->data['pages']=$page_data["pages"];
        $this->data['page']=$page;      
        $this->data['sort']=$sort;
        $this->data['state']=$state;
        

        
        $keyword = array(
                'name'      => 'keyword',
                'id'        => 'keyword',
                'value'     =>  $key,
                'class'     =>  'form-control input-sm',
                'placeholder'=> '请输入关键字',
                'maxlength' => '100'
        );
		$this->data['keyword']=$keyword;
		
		//
		$this->data['content_header_title'] = content_header_title($this->data['page_title']," 列表");
		$this->data['content'] = 'aliship/record';

		//
		$this->render();
    }
    
    public function ajaxedit()
    {
        $attrName=$this->input->post("attrName");
		$newHtml=$this->input->post("newHtml");
		if(!in_array($attrName,['status','memo'])) die();
        $cid=$this->input->post("cid");
        $newdata[$attrName]=$newHtml;
        $this->aliship_model->update($cid, $newdata);
        echo json_encode([]);
        die();
    }
    
}
